package crawler.web.beans;

import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import library.database.mongo.ObjectId;
import crawler.web.engine.config.Suite;

/**
 * 页面内容
 * 
 * @author waynechen
 * 
 */
public class CrawlPageContext implements Serializable {
	public static final CrawlURL nullCrawlURL = new CrawlURL();
	public static final TagData nullTagData = new TagData();
	private static final long serialVersionUID = -2667986530939358578L;

	public void increasePerfectionScore(int inc) {
		this.perfectionScore += inc;
	}

	public void increasePerfectionScore() {
		increasePerfectionScore(5);
	}

	public static final CrawlPageContext createInitInstance() {
		CrawlPageContext inst = new CrawlPageContext();
		inst.set_id(null);
		inst.setUrl(nullCrawlURL);
		inst.setSiteDomainURL("");
		inst.setKeywords("");
		inst.setDescription("");
		inst.setUrlList(new HashSet<CrawlURL>());
		inst.setTitle(new StringBuilder());
		inst.setNavigate(new StringBuilder());
		inst.setFingerPrint(-1L);
		inst.setSimilarFingerPrintIDs(new LinkedList<ObjectId>());
		inst.setTagData(nullTagData);
		inst.setParseStatus(-1);
		inst.setSrc("");
		inst.setPerfectionScore(0);
		inst.setPageType(Suite.PageType.ERROR.getExpr());
		inst.setLocation(new Location());
		inst.setChannel(new Channel());
		inst.setSight(new Sight());
		inst.setFood(new Food());
		inst.setGood(new Good());
		return inst;
	}

	@Override
	public String toString() {
		return "CrawlPageContext\n [\n    _id=" + _id + "\n    url=" + url + "\n    siteDomainURL=" + siteDomainURL + "\n    keywords=" + keywords + "\n    description=" + description + "\n    urlList=" + urlList + "\n    title=" + title + "\n    navigate=" + navigate + "\n    fingerPrint=" + fingerPrint + "\n    similarFingerPrintIDs=" + similarFingerPrintIDs + "\n    tagData=" + tagData + "\n    parseStatus=" + parseStatus + "\n    src=" + src + "\n    perfectionScore=" + perfectionScore + "\n    pageType=" + pageType + "\n    location=" + location + "\n    channel=" + channel + "\n    sight=" + sight + "\n    food=" + food + "\n    good=" + good + "\n]";
	}

	/**
	 * mongodb中的id
	 */
	private ObjectId _id;
	/**
	 * 指向本pageContext的url
	 */
	private CrawlURL url;
	/**
	 * 网站的域名
	 */
	private String siteDomainURL;
	/**
	 * 此pageContext的关键字
	 */
	private String keywords;
	/**
	 * 此pageContext的描述
	 */
	private String description;
	/**
	 * 此pageContext中分析出的url列表
	 */
	private Set<CrawlURL> urlList;
	/**
	 * 如果有文章, 此文章的标题是title属性<br>
	 * url的锚点文字
	 */
	private StringBuilder title;
	/**
	 * 当前文章的导航路径
	 */
	private StringBuilder navigate;
	/**
	 * 网页的指纹信息
	 */
	private Long fingerPrint;
	/**
	 * 近似网页的分组信息(组号)<br>
	 * 使用其中一个网页的, 主键
	 */
	private List<ObjectId> similarFingerPrintIDs;
	/**
	 * 通用的标签数据结构<br>
	 * 收集有用的网页数据
	 */
	private TagData tagData;
	/**
	 * 此网页的分析状态, 说明在: Suite.ParseStatus类
	 */
	private Integer parseStatus;
	/**
	 * 数据操作记录
	 */
	private String src;
	/**
	 * 一个网页经过分析有, 有用的信息指数<br>
	 * 完善性分数, 越大越完善
	 */
	private Integer perfectionScore;
	/**
	 * 数据类型, 是有用数据还是垃圾数据
	 */
	private String pageType;
	/**
	 * 地址<br>
	 * 美食, 景点的唯一性判断可根据location.identity属性<br>
	 */
	private Location location;
	/**
	 * 频道
	 */
	private Channel channel;
	/**
	 * 网页是景点<br>
	 * 只存入景点相关的, 不存入地址
	 */
	private Sight sight;
	/**
	 * 网页是美食<br>
	 * 只存入美食相关的, 不存入地址
	 */
	private Food food;
	/**
	 * 网页是商品<br>
	 */
	private Good good;

	public Good getGood() {
		return good;
	}

	public void setGood(Good good) {
		this.good = good;
	}

	public Food getFood() {
		return food;
	}

	public void setFood(Food food) {
		this.food = food;
	}

	public Sight getSight() {
		return sight;
	}

	public void setSight(Sight sight) {
		this.sight = sight;
	}

	public Integer getPerfectionScore() {
		return perfectionScore;
	}

	public void setPerfectionScore(Integer perfectionScore) {
		this.perfectionScore = perfectionScore;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public Channel getChannel() {
		return channel;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public String getSrc() {
		return src;
	}

	public void setSrc(String src) {
		this.src = src;
	}

	public String getPageType() {
		return pageType;
	}

	public void setPageType(String pageType) {
		this.pageType = pageType;
	}

	public Integer getParseStatus() {
		return parseStatus;
	}

	public void setParseStatus(Integer parseStatus) {
		this.parseStatus = parseStatus;
	}

	public List<ObjectId> getSimilarFingerPrintIDs() {
		return similarFingerPrintIDs;
	}

	public void setSimilarFingerPrintIDs(List<ObjectId> similarFingerPrintIDs) {
		this.similarFingerPrintIDs = similarFingerPrintIDs;
	}

	public TagData getTagData() {
		return tagData;
	}

	public void setTagData(TagData tagData) {
		this.tagData = tagData;
	}

	public Long getFingerPrint() {
		return fingerPrint;
	}

	public void setFingerPrint(Long fingerPrint) {
		this.fingerPrint = fingerPrint;
	}

	public ObjectId get_id() {
		return _id;
	}

	public void set_id(ObjectId _id) {
		this._id = _id;
	}

	public CrawlURL getUrl() {
		return url;
	}

	public void setUrl(CrawlURL url) {
		this.url = url;
	}

	public StringBuilder getNavigate() {
		return navigate;
	}

	public void setNavigate(StringBuilder navigate) {
		this.navigate = navigate;
	}

	public String getSiteDomainURL() {
		return siteDomainURL;
	}

	public void setSiteDomainURL(String siteDomainURL) {
		this.siteDomainURL = siteDomainURL;
	}

	public StringBuilder getTitle() {
		return title;
	}

	public void setTitle(StringBuilder title) {
		this.title = title;
	}

	public Set<CrawlURL> getUrlList() {
		return urlList;
	}

	public void setUrlList(Set<CrawlURL> urlList) {
		this.urlList = urlList;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
